package ${basePackage}.domain.web;

import ${basePackage}.base.ModelWrapper;
import ${basePackage}.base.Result;
import ${basePackage}.base.ResultGenerator;
import ${basePackage}.base.DataTables;
import ${basePackage}.domain.model.${modelNameUpperCamel};
import ${basePackage}.domain.service.${modelNameUpperCamel}Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import java.util.List;

/**
* Created by ${author} on ${date}.
*/
@RestController
@RequestMapping("${baseRequestMapping}")
public class ${modelNameUpperCamel}Controller {

    @Resource
    private ${modelNameUpperCamel}Service ${modelNameLowerCamel}Service;

    @PostMapping("/add")
    public Result add(${modelNameUpperCamel} ${modelNameLowerCamel}) {
        ${modelNameLowerCamel}Service.save(${modelNameLowerCamel});
        return ResultGenerator.genSuccessResult();
    }

    @ApiOperation(value = "根据 id 删除 ${modelNameUpperCamel}")
    @GetMapping("/delete")
    public Result delete(@RequestParam Long id) {
        ${modelNameLowerCamel}Service.deleteById(id);
        return ResultGenerator.genSuccessResult();
    }

    @ApiOperation(value = "根据 ids 批量删除 ${modelNameUpperCamel}")
    @GetMapping("/deleteByIds")
    public Result deleteByIds(@RequestParam String ids) {
        ${modelNameLowerCamel}Service.deleteByIds(ids);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    public Result update(${modelNameUpperCamel} ${modelNameLowerCamel}) {
        ${modelNameLowerCamel}Service.update(${modelNameLowerCamel});
        return ResultGenerator.genSuccessResult();
    }

    @ApiOperation(value = "根据 id 查询 ${modelNameUpperCamel}")
    @GetMapping("/detail")
    public Result detail(@RequestParam Long id) {
        ${modelNameUpperCamel} ${modelNameLowerCamel} = ${modelNameLowerCamel}Service.findById(id);
        return ResultGenerator.genSuccessResult(${modelNameLowerCamel});
    }

    @ApiOperation(value = "按条件查询 ${modelNameUpperCamel}")
    @PostMapping("/listByCondition")
    public Result listByCondition(@RequestBody ${modelNameUpperCamel} ${modelNameLowerCamel}) {
        List<${modelNameUpperCamel}> list = ${modelNameLowerCamel}Service.findByModel(${modelNameLowerCamel});
        return ResultGenerator.genSuccessResult(list);
    }

    @ApiOperation(value = "按条件查询 ${modelNameUpperCamel}")
    @PostMapping("/listByModelWrapper")
    public Result listByModelWrapper(@RequestBody ModelWrapper<${modelNameUpperCamel}> wrapper) {
        List<${modelNameUpperCamel}> list = ${modelNameLowerCamel}Service.findByModelWrapper(wrapper);
        return ResultGenerator.genSuccessResult(list);
    }

    @ApiOperation(value = "分页查询 ${modelNameUpperCamel}")
    @GetMapping("/list")
    public Result list(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size) {
        PageHelper.startPage(page, size);
        List<${modelNameUpperCamel}> list = ${modelNameLowerCamel}Service.findAll();
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }

    @ApiOperation(value = "按条件分页查询 ${modelNameUpperCamel}")
    @PostMapping("/page")
    public DataTables<${modelNameUpperCamel}> page(DataTables<${modelNameUpperCamel}> dataTables) {
        return ${modelNameLowerCamel}Service.page(dataTables);
    }
}
